﻿using System.Web.Mvc;

namespace Fx.Mvc.Language
{
    public static class LanguageHelper
    {
        private static readonly LanguageProvider _languageProvider;

        static LanguageHelper()
        {
            _languageProvider = new LanguageProvider();
            _languageProvider.LoadLanguage("languages");
        }

        public static string Lang(this HtmlHelper helper, string key)
        {
            var value = _languageProvider.Translate(key, key);
            return value;
        }

        public static string Lang(this HtmlHelper helper, string key, string defaultValue)
        {
            var value = _languageProvider.Translate(key, key);
            return value == key ? defaultValue : value;
        }

        public static string Lang(string key)
        {
            var value = _languageProvider.Translate(key, key);
            return value;
        }

        public static string Lang(string key, string defaultValue)
        {
            var value = _languageProvider.Translate(key, key);
            return value == key ? defaultValue : value;
        }
    }
}